<?php
    session_start();
    if($_SESSION['uid']==""||$_SESSION['level']!=3){
        header("Location: ../exit.php");
        exit();
    }

    include('/tool/submitValidate.php');
    include('/tool/pdo.php');
    include('/class/apartment.class.php');
    include('/bll/ApartmentBLL.php');

    $action = isset($_POST['action']) ? $_POST['action'] : 0;
    $data = isset($_POST['data']) ? $_POST['data'] : "";

    $message=array();
    switch((int)$action){
        //1：获取页面信息
        case 1:
            //将json字符串转换为php对象
            $dataObject=json_decode($data);
            $apartment=new ApartmentBLL();
            $message=$apartment->getApartmentInformation($dataObject);
        break;
        //修改公寓信息
        case 2:
            $dataObject=json_decode($data);
            $apartment=new ApartmentBLL();
            $message=$apartment->modifyApartmentInformation($dataObject);
        break;
        //获取各层的信息
        case 3:
            $dataObject=json_decode($data);
            $apartment=new ApartmentBLL();
            $message=$apartment->getApartmentFloorInformation($dataObject);
        break;
        //获取各层宿舍的信息（列表）
        case 4:
            $dataObject=json_decode($data);
            $apartment=new ApartmentBLL();
            $message=$apartment->getApartmentDormitoryList($dataObject);
        break;
        //查找宿舍
        case 5:
            $dataObject=json_decode($data);
            $apartment=new ApartmentBLL();
            $message=$apartment->selectDormitory($dataObject);
        break;
        //修改宿舍设置
        case 6:
            $dataObject=json_decode($data);
            $apartment=new ApartmentBLL();
            $message=$apartment->modifyDormitoryStting($dataObject);
        break;
        //获取每层宿舍页数
        case 7:
            $dataObject=json_decode($data);
            $apartment=new ApartmentBLL();
            $message=$apartment->getDormitoryListPage($dataObject);
        break;
        default:break;
    }
    echo json_encode($message,JSON_UNESCAPED_UNICODE);
?>